<template>
  <h1>作业:员工列表练习</h1>
  <el-form style="width: 500px; margin: 0 auto;" label-width="80">
    <el-form-item label="姓名">
      <el-input placeholder="请输入您的姓名" v-model="data.name"></el-input>
    </el-form-item>
    <el-form-item label="工资">
      <el-input placeholder="请输入您的工资" v-model="data.salary"></el-input>
    </el-form-item>
    <el-form-item label="岗位">
      <el-input placeholder="请输入您的岗位" v-model="data.job"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="success" @click="addEmp">点我提交</el-button>
    </el-form-item>
  </el-form>
  <el-table :data="f" style="width: 100%" >
    <el-table-column type="index" label="编号" width="180" align="center"></el-table-column>
    <el-table-column prop="name" label="姓名" width="180" ></el-table-column>
    <el-table-column prop="salary" label="工资" width="180"></el-table-column>
    <el-table-column prop="job" label="工作"></el-table-column>
    <el-table-column label="操作" align="center">
      <template #default="scope">
        <el-button type="danger" @click="del(scope.row,scope.$index)">删除</el-button>
      </template>
    </el-table-column>
  </el-table>
</template>

<script setup>
import {ref} from "vue";
import {ElMessage} from "element-plus";

const f=ref([]);
const data=ref({
  name:"",
  salary:"",
  job:""
})

const addEmp=()=>{
  if(data.value.name==""||data.value.salary==""||data.value.job==""){
    ElMessage.error("请填写完整信息");
    // alert("请填写完整信息");
    return;
  }
  f.value.push(data.value);
  data.value={name:"",salary:"",job:""};
  console.log(f.value);
}
//定义删除员工的方法
const del = (data,index) =>{
  if(confirm('确定删除'+data.name+'吗？')){
    f.value.splice(index,1);
    ElMessage.success("删除成功");
  }
}
</script>


<style scoped>

</style>